﻿using CPF.Drawing;
using CPF.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPFUI.IHelper
{
    public static class ControlHelper
    {
        /// <summary>
        /// 颜色加深
        /// </summary>
        /// <param name="color"></param>
        /// <param name="depth">-1.0f <= depth <= 1.0f</param>
        /// <returns></returns>
        public static Color ColorDepthVariationChange(this Color color, float depth)
        {
            float red = (float)color.R;
            float green = (float)color.G;
            float blue = (float)color.B;

            if (depth < 0)
            {
                depth = 1 + depth;
                red *= depth;
                green *= depth;
                blue *= depth;
            }
            else
            {
                red = (255 - red) * depth + red;
                green = (255 - green) * depth + green;
                blue = (255 - blue) * depth + blue;
            }

            if (red < 0) red = 0;

            if (red > 255) red = 255;

            if (green < 0) green = 0;

            if (green > 255) green = 255;

            if (blue < 0) blue = 0;

            if (blue > 255) blue = 255;



            return Color.FromArgb(color.A, (byte)red, (byte)green, (byte)blue);
        }

        public static string KeyToString(this Keys key)
        {
            if ((int)key >= 34 && (int)key <= 43)
            {
                return key.ToString().Substring(1);
            }
            switch (key)
            {
                case Keys.None:
                    return "";
                case Keys.Escape:
                    return "Esc";
                case Keys.Space:
                    return "空格";
                case Keys.Back:
                    return "删除";
                case Keys.Up:
                    return "↑";
                case Keys.Left:
                    return "←";
                case Keys.Right:
                    return "→";
                case Keys.Down:
                    return "↓";
                case Keys.LeftCtrl:
                    return "Ctrl";
                case Keys.RightCtrl:
                    return "Ctrl";
                case Keys.LeftShift:
                    return "Shift";
                case Keys.RightShift:
                    return "Shift";
                case Keys.CapsLock:
                    return "Caps";
                case Keys.Delete:
                    return "Del";
                case Keys.PageUp:
                    return "PgUp";
                case Keys.PageDown:
                    return "PgDn";
                case Keys.NumPad0:
                    return "0";
                case Keys.NumPad1:
                    return "1";
                case Keys.NumPad2:
                    return "2";
                case Keys.NumPad3:
                    return "3";
                case Keys.NumPad4:
                    return "4";
                case Keys.NumPad5:
                    return "5";
                case Keys.NumPad6:
                    return "6";
                case Keys.NumPad7:
                    return "7";
                case Keys.NumPad8:
                    return "8";
                case Keys.NumPad9:
                    return "9";
                case Keys.Divide:
                    return "/";
                case Keys.Multiply:
                    return "*";
                case Keys.Subtract:
                    return "-";
                case Keys.Add:
                    return "+";
                default:
                    return key.ToString() ;
            }
            return "";
        }
    }
}
